package com.phiture.erp.produce.dal.mapper;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.phiture.erp.produce.dal.entity.ErpMaterialRequirementPlanItemsDO;
import com.phiture.erp.produce.dal.entity.ErpProductionTaskMaterialDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 生产任务单物料清单 Mapper
 *
 * @author YH
 */
@Mapper
public interface ErpProductionTaskMaterialMapper extends BaseMapperX<ErpProductionTaskMaterialDO> {

    default List<ErpProductionTaskMaterialDO> selectListByProductionTaskId(Long productionTaskId, Long processId) {
        // 根据两个参数进行查询，哪个有值就查询哪个，使用lambda表达式来动态构建查询条件
        return selectList(new LambdaQueryWrapperX<ErpProductionTaskMaterialDO>()
                .eq(productionTaskId != null, ErpProductionTaskMaterialDO::getProductionTaskId, productionTaskId)
                .eq(processId != null, ErpProductionTaskMaterialDO::getProcessId, processId));

    }

    default int deleteByProductionTaskId(Long productionTaskId) {
        return delete(ErpProductionTaskMaterialDO::getProductionTaskId, productionTaskId);
    }

}
